#include<iostream>
#include<string>
#include<cstdlib>
#include<cmath>
#include<ctime>
enum finger{
    stone, scissor,rag
};
enum state{
    lose,draw,win
};

bool isFinger(int i){
    return i==0||i==1||i==2;
}
finger i2finger(int i){
    switch(i){
    case 0:
        return stone;
    case 1:
        return scissor;
    case 2://default
        return rag;
    }
}
std::string finger2str(finger f){
    switch(f){
        case stone:
            return "stone";
        case scissor:
            return "scissor";
        case rag:
            return "rag";
    }
}
std::string state2str(state s,bool first=true){
        switch(s){
        case lose:
            return first?"lose":"win";
        case win:
            return first?"win":"lose";
        case draw:
            return "get a draw";
    }
}
finger getFinger(){
    int i=0;
    do{
        std::cout<<"你选择出 : ";
        std::cin>>i;
    }while(!isFinger(i));
    return i2finger(i);
}
// return the state of the lhs
state winner(finger lhs,finger rhs){
    if(lhs-rhs==-1||lhs-rhs==2)
        return state::win;
    else if(lhs==rhs)
        return state::draw;
    else
        return state::lose;
}
state justice(state s,bool first=true){
    auto end=state2str(s,first);
    std::cout<<"you "<<end<<std::endl;
    if(end=="win"){
        return win;
    }else if(end=="draw")
        return draw;
    else return lose;
}
state fingerGuess(bool first=true){
    std::cout<<"欢迎来到 石头剪刀布 游戏"<<std::endl;
    std::cout<<"you go ";
    if(first)
        std::cout<<"first";
    else
        std::cout<<"last";
    std::cout<<std::endl;
    std::cout<<"0 for stone;\n1 for scissor;\n2 for rag;"<<std::endl;
    srand((unsigned)time(0));
    finger com=i2finger(rand()%3);
    finger you=getFinger();
    std::cout<<"you give "<<finger2str(you)<<std::endl;
    std::cout<<"computer gets "<<finger2str(com)<<std::endl;
    return justice(winner(you,com),first);
}
void simpleGame(){
    std::cout<<"欢迎来到 石头剪刀布 游戏"<<std::endl;
    std::cout<<"0 是 石头;\n1 是 剪刀;\n2 是 布;"<<std::endl;
    std::cout<<"你出 : ";
    int i;
    do{
        std::cin>>i;
    }while(!(i==0||i==1||i==2));
    // srand((unsigned)time(0));
    int com=rand()%3;
    std::cout<<"电脑出 : "<<com<<std::endl;
    if(i-com==-1||i-com==2){
        std::cout<<"你赢了"<<std::endl;
    }else if(i==com){
        std::cout<<"平局"<<std::endl;
    }else{
        std::cout<<"你输了"<<std::endl;
    }
}
int main(){
    simpleGame();
    return 0;
}